package apis

import (
	"gitee.com/byx_darwin/ncloud-go/core"
	"gitee.com/byx_darwin/ncloud-go/core/net/consts"
	"strconv"
)

type QueryContentConditions struct {
	TaskID    string `json:"task_id"`
	StartTime int64  `json:"start_time"`
	EndTime   int64  `json:"end_time"`
}
type QueryContentRequest struct {
	core.NCloudRequest
	QueryContentConditions
}

func NewQueryContentRequestWithTaskID(taskID string) *QueryContentRequest {
	return &QueryContentRequest{
		NCloudRequest: core.NCloudRequest{
			Path:   "/content",
			Method: consts.MethodGet,
		},
		QueryContentConditions: QueryContentConditions{
			TaskID: taskID,
		},
	}
}

func NewQueryContentRequestWithTime(startTime, endTime int64) *QueryContentRequest {
	return &QueryContentRequest{
		NCloudRequest: core.NCloudRequest{
			Path:   "/content",
			Method: consts.MethodGet,
		},
		QueryContentConditions: QueryContentConditions{
			StartTime: startTime,
			EndTime:   endTime,
		},
	}
}

func (q *QueryContentRequest) GetPath() string {
	path := q.Path
	if q.TaskID != "" {
		path += "?task_id=" + q.TaskID
	} else {
		path += "?start_time=" + strconv.Itoa(int(q.StartTime)) + "&end_time=" + strconv.Itoa(int(q.EndTime))
	}
	return path
}

type ContentTaskObject struct {
	TaskId string `json:"task_id"`
	Url    string `json:"url"`
	State  int8   `json:"state"`
}
type ContentTaskData struct {
	TaskList []ContentTaskObject `json:"task_list"`
}
type QueryContentTaskResponse struct {
	Ok      bool            `json:"ok"`
	Msg     string          `json:"msg"`
	Data    ContentTaskData `json:"data,omitempty"`
	TrackID string          `json:"track_id"`
}
